
import { ref, } from "vue";
import store from "@/store";
import i18n from '@/lang/index.js'
const { locale, t } = i18n.global
locale.value = store.state.languageStatus || "zh";
// 初始化主题
const isDark = ref(true);

const useInit = ()=>{
    isDark.value = localStorage.getItem("theme") == "light" ? false : true;
    document.documentElement.classList.add(
        `van-doc-theme-${isDark.value ? "dark" : "light"}`
    );
    document.documentElement.classList.add(
        `${isDark.value ? "dark" : "light"}_theme`
    );
    store.commit("addTheme", isDark.value ? "dark" : "light");
}
const changeTheme = () => {
    let oldVal = isDark.value ? "dark" : "light";
    let newVal = !isDark.value ? "dark" : "light";
    document.documentElement.classList.remove(`van-doc-theme-${oldVal}`);
    document.documentElement.classList.remove(`${oldVal}_theme`);
    // 添加新主题样式
    document.documentElement.classList.add(`van-doc-theme-${newVal}`);
    document.documentElement.classList.add(`${newVal}_theme`);
    isDark.value = !isDark.value;
    localStorage.setItem("theme", isDark.value ? "dark" : "light");
    store.commit("addTheme", isDark.value ? "dark" : "light");
};
//初始化多语言


export {
    isDark,
    useInit,
    changeTheme
}